package com.bean;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @Author: tgy
 * @Date: 2020-07-31 15:37
 */

/**
 * 创建复杂对象，使用 FactoryBean
 */
public class MyFactoryBean implements FactoryBean<Connection> {
    @Override
    public Connection getObject() throws Exception {

        Class.forName("com.mysql.cj.jdbc.Driver");

        Connection connection = DriverManager.getConnection("jdbc:mysql://47.99.51.246:3306/crud?useSSL=false", "option", "oqu_aiy8vaey<oGho1baw0ye");

        return connection;
    }

    @Override
    public Class<?> getObjectType() {

        return Connection.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
